In a virtualization environment, from a perspective of a virtual machine, a virtual CPU is used to execute calculation, but essentially, a calculation function is executed by a physical CPU of a physical host on which the virtual machine is located. In a multi-core environment, when multiple physical CPUs and multiple virtual CPUs exist, a problem about how to map a virtual CPU to a physical CPU occurs.
In the prior art, to resolve the problem about how to map a virtual CPU to a physical CPU, each physical CPU manages a queue of virtual CPUs that can run locally. A priority of each virtual CPU has two statuses, scheduled (over) and to-be-scheduled (under). During scheduling, a scheduler preferentially schedules a virtual CPU whose current status is under, and if a physical CPU running queue does not have a virtual CPU whose priority is under, a virtual CPU whose priority is under is found from another CPU running queue.
However, in the prior art, virtual CPUs whose priorities are under may run tasks of a same task type. Because a resource contention factor is not considered when mapping a virtual CPU and a physical CPU, virtual CPUs that run tasks of a same task type may usually be mapped to different physical CPUs for running simultaneously, and technical problems of resource contention and a decrease in overall system performance exist.